import axios from 'axios';
import { defineStore } from "pinia";
import { Channels, ChannelsRes } from '../../types/data';
//导出
export default defineStore('channel',{
  state() {
    return {
      channels :[] as Channels ,  // as
      curId :0 //当前选中频道的id
    }
  },
  actions: {
    setCurId(newId:number){
      this.curId = newId
    },
    async getChannel() {
      const {data:{data:{channels:res}}} = await axios.get<ChannelsRes>('http://geek.itheima.net/v1_0/channels')
      console.log(res);
      this.channels = res
      this.curId = res[0].id
      //this.curId = this.channels[0].id
      //console.log(res.data.data.channels)
  }
  }
}) 